/**    
 * 文件名：JavaSiftDiscriptorImpl.java    
 *    
 * 版本信息：    
 * 日期：2014年3月6日    
 * xyj 足下 xyj 2014     
 * 版权所有    
 *    
 */
package com.joey.opencv.test.impl;

import static com.googlecode.javacv.cpp.opencv_core.cvCreateImage;
import static com.googlecode.javacv.cpp.opencv_core.cvReleaseImage;
import static com.googlecode.javacv.cpp.opencv_core.cvSize;
import static com.googlecode.javacv.cpp.opencv_highgui.cvLoadImage;
import static com.googlecode.javacv.cpp.opencv_imgproc.CV_RGB2GRAY;
import static com.googlecode.javacv.cpp.opencv_imgproc.cvCvtColor;
import static com.googlecode.javacv.cpp.opencv_imgproc.cvResize;

import com.googlecode.javacv.cpp.opencv_core.IplImage;
import com.googlecode.javacv.cpp.opencv_features2d.KeyPoint;
import com.googlecode.javacv.cpp.opencv_nonfree.SIFT;
import com.joey.opencv.test.JavaSiftDiscriptor;

/**
 * @项目名称：opencv-test
 * @类名称：JavaSiftDiscriptorImpl
 * @类描述：
 * @创建人：zhuyi
 * @创建时间：2014年3月6日 下午4:57:39
 * @修改人：zhuyi
 * @修改时间：2014年3月6日 下午4:57:39
 * @修改备注：
 * @version
 * 
 */
public class JavaSiftDiscriptorImpl implements JavaSiftDiscriptor {

    private String imgName;

    private int interestPointNumber;

    private KeyPoint featureArray;

    /*
     * (non-Javadoc)
     * 
     * @see com.joey.opencv.test.JavaSiftDiscriptor#calculateSift()
     */
    @Override
    public int calculateSift() {

        IplImage pInputImg = cvLoadImage(this.imgName);

        // 训练用标准图像大小
        int nImgWidth = 320;
        double dbScaleFactor = pInputImg.width() / 300.0;
        IplImage pTmpImg = cvCreateImage(cvSize(pInputImg.width(), pInputImg.height()), pInputImg.depth(),
                pInputImg.nChannels());

        cvResize(pInputImg, pTmpImg);
        cvReleaseImage(pInputImg);

        // 非灰度图
        if (pTmpImg.nChannels() != 1) {
            IplImage pGrayImg = cvCreateImage(cvSize(pTmpImg.width(), pTmpImg.height()), pTmpImg.depth(), 1);
            cvCvtColor(pTmpImg, pGrayImg, CV_RGB2GRAY);
            interestPointNumber = 
        }

        return 0;
    }

    public KeyPoint siftFeatures(IplImage image) {

        KeyPoint keyPoints = new KeyPoint();
        int nFeatures = 0;
        int nOctaveLayers = 3;
        float contrastThreshold = 0.03f;
        int edgeThreshold = 10;
        float sigma = 1.6f;
        SIFT sift = new SIFT(nFeatures, nOctaveLayers, contrastThreshold, edgeThreshold, sigma);
        sift.detect(image, null, keyPoints);

        return keyPoints;

    }

    /*
     * (non-Javadoc)
     * 
     * @see com.joey.opencv.test.JavaSiftDiscriptor#setImgName(java.lang.String)
     */
    @Override
    public void setImgName(String imageName) {
        this.imgName = imageName;
    }

    /*
     * (non-Javadoc)
     * 
     * @see com.joey.opencv.test.JavaSiftDiscriptor#getInterestPointNumber()
     */
    @Override
    public int getInterestPointNumber() {
        return interestPointNumber;
    }

}
